/********************************************************************************
 * @file    main.h
 * @author  jianqiang.xue
 * @version V1.0.0
 * @date    2023-08-16
 * @brief   main function
 ******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __MAIN_H
#define __MAIN_H

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "cx32l003_hal.h"
#include "cx32l003_starterkit.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "io_mapping.h"
#include "log.h"
#include "util.h"
#include <stdbool.h>
/* USER CODE END Includes */


/* Exported functions prototypes ---------------------------------------------*/
void Error_Handler(void);


/* Private defines -----------------------------------------------------------*/

typedef struct {
    uint16_t bit0 : 1;
    uint16_t bit1 : 1;
    uint16_t bit2 : 1;
    uint16_t bit3 : 1;
    uint16_t bit4 : 1;
    uint16_t bit5 : 1;
    uint16_t bit6 : 1;
    uint16_t bit7 : 1;
    uint16_t bit8 : 1;
    uint16_t bit9 : 1;
    uint16_t bit10 : 1;
    uint16_t bit11 : 1;
    uint16_t bit12 : 1;
    uint16_t bit13 : 1;
    uint16_t bit14 : 1;
    uint16_t bit15 : 1;
} Bits_16_TypeDef;

#define PAout(n) ((Bits_16_TypeDef *)(&(GPIOA->ODR)))->bit##n
#define PBout(n) ((Bits_16_TypeDef *)(&(GPIOB->ODR)))->bit##n
#define PCout(n) ((Bits_16_TypeDef *)(&(GPIOC->ODR)))->bit##n
#define PDout(n) ((Bits_16_TypeDef *)(&(GPIOD->ODR)))->bit##n

#define PAin(n) ((Bits_16_TypeDef *)(&(GPIOA->IDR)))->bit##n
#define PBin(n) ((Bits_16_TypeDef *)(&(GPIOB->IDR)))->bit##n
#define PCBin(n) ((Bits_16_TypeDef *)(&(GPIOC->IDR)))->bit##n
#define PDBin(n) ((Bits_16_TypeDef *)(&(GPIOD->IDR)))->bit##n

#ifdef __cplusplus
}
#endif

#endif /* __MAIN_H */

